/*   1:    */ package tt.dz.common;
/*   2:    */ 
/*   3:    */ import java.io.PrintStream;
/*   4:    */ import java.util.ArrayList;
/*   5:    */ import java.util.List;
/*   6:    */ import java.util.Random;
/*   7:    */ import java.util.regex.Matcher;
/*   8:    */ import java.util.regex.Pattern;
/*   9:    */ 
/*  10:    */ public class DZStringUtil
/*  11:    */ {
/*  12:    */   public static String getRandomCode()
/*  13:    */   {
/*  14: 17 */     return getRandomCode(6);
/*  15:    */   }
/*  16:    */   
/*  17:    */   public static String getRandomCode(int num)
/*  18:    */   {
/*  19: 28 */     int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
/*  20: 29 */     Random rand = new Random();
/*  21: 30 */     for (int i = 10; i > 1; i--)
/*  22:    */     {
/*  23: 31 */       int index = rand.nextInt(i);
/*  24: 32 */       int tmp = array[index];
/*  25: 33 */       array[index] = array[(i - 1)];
/*  26: 34 */       array[(i - 1)] = tmp;
/*  27:    */     }
/*  28: 36 */     StringBuffer randomCode = new StringBuffer();
/*  29: 37 */     for (int i = 0; i < num; i++) {
/*  30: 38 */       randomCode.append(array[i]);
/*  31:    */     }
/*  32: 39 */     return randomCode.toString();
/*  33:    */   }
/*  34:    */   
/*  35:    */   public static String getFixedLengthString(int totalLen, String res)
/*  36:    */   {
/*  37: 52 */     int len = 0;
/*  38: 53 */     String resStr = null;
/*  39: 54 */     if ((null == res) || (res.trim().length() == 0))
/*  40:    */     {
/*  41: 55 */       len = totalLen;
/*  42: 56 */       resStr = "";
/*  43:    */     }
/*  44:    */     else
/*  45:    */     {
/*  46: 58 */       len = totalLen - res.length();
/*  47: 59 */       resStr = res.trim();
/*  48:    */     }
/*  49: 61 */     StringBuilder rs = new StringBuilder();
/*  50: 62 */     for (int i = 0; i < len; i++) {
/*  51: 63 */       rs.append("0");
/*  52:    */     }
/*  53: 65 */     return resStr;
/*  54:    */   }
/*  55:    */   
/*  56:    */   public static String getRandomString(int length)
/*  57:    */   {
/*  58: 75 */     String base = "abcdefghijklmnopqrstuvwxyz0123456789";
/*  59: 76 */     Random random = new Random();
/*  60: 77 */     StringBuilder sb = new StringBuilder();
/*  61: 78 */     for (int i = 0; i < length; i++)
/*  62:    */     {
/*  63: 79 */       int number = random.nextInt(base.length());
/*  64: 80 */       sb.append(base.charAt(number));
/*  65:    */     }
/*  66: 82 */     return sb.toString();
/*  67:    */   }
/*  68:    */   
/*  69:    */   public static Integer createVerifyCode(String sourceCode)
/*  70:    */   {
/*  71: 94 */     List<Integer> oddList = new ArrayList();
/*  72: 95 */     List<Integer> evenList = new ArrayList();
/*  73: 96 */     boolean isOdd = true;
/*  74: 97 */     for (int i = 0; i < sourceCode.length(); i++) {
/*  75: 98 */       if (isOdd)
/*  76:    */       {
/*  77: 99 */         oddList.add(Integer.valueOf(Integer.parseInt(sourceCode.charAt(i) + "")));
/*  78:100 */         isOdd = false;
/*  79:    */       }
/*  80:    */       else
/*  81:    */       {
/*  82:102 */         evenList.add(Integer.valueOf(Integer.parseInt(sourceCode.charAt(i) + "")));
/*  83:103 */         isOdd = true;
/*  84:    */       }
/*  85:    */     }
/*  86:106 */     Integer oddSum = Integer.valueOf(0);
/*  87:107 */     Integer evenSum = Integer.valueOf(0);
/*  88:108 */     for (Integer i : evenList) {
/*  89:109 */       evenSum = Integer.valueOf(evenSum.intValue() + i.intValue());
/*  90:    */     }
/*  91:111 */     for (Integer i : oddList)
/*  92:    */     {
/*  93:112 */       int t = i.intValue() * 2;
/*  94:113 */       oddSum = Integer.valueOf(oddSum.intValue() + t / 10 + t % 10);
/*  95:    */     }
/*  96:115 */     return Integer.valueOf((10 - (oddSum.intValue() + evenSum.intValue()) % 10) % 10);
/*  97:    */   }
/*  98:    */   
/*  99:    */   public static boolean verifyMobileNo(String mobileNo)
/* 100:    */   {
/* 101:126 */     if (mobileNo == null) {
/* 102:127 */       throw new IllegalArgumentException("parameter mobileNo can't be empty");
/* 103:    */     }
/* 104:128 */     String regex = "^1(3|4|5|7|8){1}\\d{9}$";
/* 105:129 */     return regular(mobileNo, regex);
/* 106:    */   }
/* 107:    */   
/* 108:    */   public static boolean verifyItude(String itude)
/* 109:    */   {
/* 110:140 */     if (itude == null) {
/* 111:141 */       throw new IllegalArgumentException("parameter itude can't be empty");
/* 112:    */     }
/* 113:142 */     String regex = "^\\d{1,3}(\\.\\d{1,6})?";
/* 114:143 */     return regular(itude, regex);
/* 115:    */   }
/* 116:    */   
/* 117:    */   public static boolean verifyValueInEnums(String value, String... enums)
/* 118:    */   {
/* 119:160 */     if (value == null) {
/* 120:161 */       throw new IllegalArgumentException("parameter value can't be empty");
/* 121:    */     }
/* 122:162 */     if (enums.length > 0)
/* 123:    */     {
/* 124:163 */       StringBuffer regex = new StringBuffer("^(");
/* 125:164 */       for (String key : enums) {
/* 126:165 */         regex.append(key + "|");
/* 127:    */       }
/* 128:167 */       regex.deleteCharAt(regex.length() - 1);
/* 129:168 */       regex.append(")$");
/* 130:169 */       return regular(value, regex.toString());
/* 131:    */     }
/* 132:171 */     throw new IllegalArgumentException("parameter enums must be exists");
/* 133:    */   }
/* 134:    */   
/* 135:    */   public static boolean isEmpty(String s)
/* 136:    */   {
/* 137:183 */     if ((s == null) || ("".equals(s))) {
/* 138:184 */       return true;
/* 139:    */     }
/* 140:186 */     return false;
/* 141:    */   }
/* 142:    */   
/* 143:    */   public static boolean verifyEmail(String emailAddress)
/* 144:    */   {
/* 145:197 */     if (emailAddress == null) {
/* 146:198 */       throw new IllegalArgumentException("parameter emailAddress can't be empty");
/* 147:    */     }
/* 148:199 */     String regex = "\\w+(\\.\\w+)*@\\w+(\\.\\w+)+";
/* 149:200 */     return regular(emailAddress, regex);
/* 150:    */   }
/* 151:    */   
/* 152:    */   public static boolean verifyUserName(String nickName)
/* 153:    */   {
/* 154:204 */     if (nickName == null) {
/* 155:205 */       throw new IllegalArgumentException("parameter can't be empty");
/* 156:    */     }
/* 157:206 */     String regex = "[a-zA-Z0-9_]+$";
/* 158:207 */     return regular(nickName, regex);
/* 159:    */   }
/* 160:    */   
/* 161:    */   private static boolean regular(String inputstr, String regex)
/* 162:    */   {
/* 163:211 */     Pattern p = Pattern.compile(regex);
/* 164:212 */     Matcher m = p.matcher(inputstr);
/* 165:213 */     return m.matches();
/* 166:    */   }
/* 167:    */   
/* 168:    */   public static void main(String[] args)
/* 169:    */   {
/* 170:217 */     System.out.println(verifyUserName("___dsfaff_009"));
/* 171:    */   }
/* 172:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.common.DZStringUtil
 * JD-Core Version:    0.7.0.1
 */